//
//  ExerciseRootViewController.m
//  Founder_study
//
//  Created by hongbao.cui on 14-8-21.
//  Copyright (c) 2014年 com.founder. All rights reserved.
//

#import "ExerciseRootViewController.h"
#import "FMSNetWorkModule.h"
#import "ZipArchive.h"
#import "SynExericisesPaperData.h"
#import "Sqlite.h"
#import "SwipeView.h"
#import "ApplicationUtils.h"
#import "PaperListView.h"
#import "XingAndLabel_UIView.h"
#import "ISMutileButton.h"
#import "ApplicationUtils.h"
#import "CaseQuestionView.h"
#import "HBListTableView.h"
#import "HBTableViewFooterView.h"
@interface ExerciseRootViewController ()<SwipeViewDataSource,SwipeViewDelegate,PaperListViewDelegate,HBListTableViewDelegate,HBTableViewFooterViewDelegate>{
    
}
@end

@implementation ExerciseRootViewController
@synthesize answerArray;
@synthesize paperArray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)initSelfView{
    //header
    headerBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, FMSCREENWIDTH,30)];
    [headerBg setBackgroundColor:[ApplicationUtils stringTOColor:@"#2d2927"]];
    [self.view addSubview:headerBg];
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, FMSCREENWIDTH, 30)];
    [titleLabel setText:@""];
    [titleLabel setTextColor:[UIColor whiteColor]];
    [titleLabel setNumberOfLines:0];
    [titleLabel setLineBreakMode:NSLineBreakByWordWrapping];
    [titleLabel setFont:[UIFont systemFontOfSize:13.0]];
    [titleLabel setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:titleLabel];
    
    //footer
    UIImage *footerBg = [ApplicationUtils getLocalImage:@"app_footer_bg"];
    UIImageView *footer = [[UIImageView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-20-44-50, FMSCREENWIDTH, 50)];
    [footer setImage:footerBg];
    //上一页
//    UIButton *upButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [upButton setBackgroundImage:[UIImage getLocalImage:@"exam_icon_previous"] forState:UIControlStateNormal];
//    [upButton setBackgroundImage:[UIImage getLocalImage:@"exam_icon_previous_pressed"] forState:UIControlStateHighlighted];
//    [upButton setTitle:@"上一页" forState:UIControlStateNormal];
//    [upButton setTitle:@"上一页" forState:UIControlStateHighlighted];
//    [[upButton titleLabel] setFont:[UIFont systemFontOfSize:8.0]];
//    [upButton setTitleEdgeInsets:UIEdgeInsetsMake(35, 0, 0, 0)];
//    [upButton setFrame:CGRectMake(20, (50-30)/2, 25, 25)];
//    [upButton addTarget:self action:@selector(upBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [footer addSubview:upButton];
    
    //答案
    UIButton *answerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [answerButton setImage:[ApplicationUtils getLocalImage:@"st_Options_submit1@2x"] forState:UIControlStateNormal];
    [answerButton setImage:[ApplicationUtils getLocalImage:@"st_Options_submit@2x"] forState:UIControlStateHighlighted];
    [answerButton setBackgroundColor:[UIColor clearColor]];
    [answerButton setTitle:@"答案" forState:UIControlStateNormal];
    [answerButton setTitle:@"答案" forState:UIControlStateHighlighted];
    [answerButton setTitleColor:[ApplicationUtils stringTOColor:@"#1cb6a7"] forState:UIControlStateHighlighted];
    [answerButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [answerButton setImageEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 25)];
    [[answerButton titleLabel] setFont:[UIFont systemFontOfSize:14.0]];
    [answerButton setFrame:CGRectMake(FMSCREENWIDTH/2-100, 0, 100, 50)];
    [answerButton setContentMode:UIViewContentModeCenter];
    [answerButton addTarget:self action:@selector(answerBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:answerButton];
    
    //收藏
    UIButton *favButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [favButton setImage:[ApplicationUtils getLocalImage:@"st_Options_Collection1@2x"] forState:UIControlStateNormal];
    [favButton setImage:[ApplicationUtils getLocalImage:@"st_Options_Collection@2x"] forState:UIControlStateHighlighted];
    [favButton setImage:[ApplicationUtils getLocalImage:@"st_Options_Collection@2x"] forState:UIControlStateSelected];
    [favButton setTitle:@"收藏" forState:UIControlStateNormal];
    [favButton setTitle:@"收藏" forState:UIControlStateHighlighted];
    [favButton setTitle:@"取消收藏" forState:UIControlStateSelected];
    [favButton setTitleColor:[ApplicationUtils stringTOColor:@"#1cb6a7"] forState:UIControlStateHighlighted];
    [favButton setTitleColor:[ApplicationUtils stringTOColor:@"#1cb6a7"] forState:UIControlStateSelected];
    [[favButton titleLabel] setFont:[UIFont systemFontOfSize:14.0]];
    collectionBtn= favButton;
    [favButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [favButton setImageEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 30)];
    [favButton setFrame:CGRectMake(FMSCREENWIDTH/2+50, (50-30)/2, 100, 30)];
    [favButton addTarget:self action:@selector(favBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [footer addSubview:favButton];
    //下一页
//    UIButton *downButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    [downButton setBackgroundImage:[UIImage getLocalImage:@"exam_icon_next"] forState:UIControlStateNormal];
//    [downButton setBackgroundImage:[UIImage getLocalImage:@"exam_icon_next_pressed"] forState:UIControlStateHighlighted];
//    [downButton setTitle:@"下一页" forState:UIControlStateNormal];
//    [downButton setTitle:@"下一页" forState:UIControlStateHighlighted];
//    [[downButton titleLabel] setFont:[UIFont systemFontOfSize:8.0]];
//    [downButton setTitleEdgeInsets:UIEdgeInsetsMake(35, 0, 0, 0)];
//    [downButton setFrame:CGRectMake(265, (50-30)/2, 25, 25)];
//    [downButton addTarget:self action:@selector(downBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [footer addSubview:downButton];
    
    [footer setUserInteractionEnabled:YES];
    [self.view addSubview:footer];
    
    CGRect rect = [[UIScreen mainScreen] bounds];
    int h = rect.size.height-44-35-50-20;
    _swipeView = [[SwipeView alloc] initWithFrame:CGRectMake(0, 35, FMSCREENWIDTH, h)];
    _swipeView.alignment = SwipeViewAlignmentCenter;
    _swipeView.delegate = self;
    _swipeView.dataSource = self;
    _swipeView.pagingEnabled = YES;
    _swipeView.wrapEnabled = NO;
    _swipeView.itemsPerPage = 1;
    _swipeView.truncateFinalPage = YES;
    [_swipeView setBackgroundColor:[UIColor clearColor]];
    [self.view addSubview:_swipeView];
    
}
//上一页
-(void)upBtnClicked:(UIButton *)sender{
    if (currentPage==0) {
        [ApplicationUtils makeToast:@"已第一页" withImageName:@"no" withView:self.view];
        return;
    }
    [_swipeView scrollToPage:currentPage-1 duration:0.5];
}
//答案
//-(void)answerBtnClicked:(UIButton *)sender{
//    NSDictionary *dataDict = [self.paperArray objectAtIndex:currentPage];
//    NSString *answer = [dataDict objectForKey:@"answer"];
//    NSString *orderIdStr =[dataDict objectForKey:@"orderid"];
//    NSString *titleStr =[dataDict objectForKey:@"questionContent"];
//    NSString *qtype =[dataDict objectForKey:@"qtype"];
//    NSString *anyliseHTMLData = nil;
//    NSArray  *optionsArray = [dataDict objectForKey:@"options"];
//    int h =0;
//    if ([qtype isEqualToString:@"1"]||[qtype isEqualToString:@"2"]) {
//        if ([qtype isEqualToString:@"1"]) {
//            NSString *str = [NSString stringWithFormat:@"%@.%@",orderIdStr,titleStr];
//            CGSize size_0 = CGSizeMake(FMSCREENWIDTH-20, 1000);
//            CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:16.0]constrainedToSize:size_0 lineBreakMode:NSLineBreakByWordWrapping];
//            
//            h = size.height+30;
//            NSString *imageStr = nil;
//            imageStr = @"table_yes.png";
//            if (selectionStr==nil) {
//                selectionStr = @"您没有选择答案";
//            }else{
//                if ([answer isEqualToString:selectionStr]) {//正确
//                    imageStr = @"st_Options_mark_002@2x.png";
//                }else{
//                    imageStr = @"st_Options_mark_001@2x.png";
//                }
//            }
//            anyliseHTMLData = [NSString stringWithFormat:@"<p><a><font color=\"#0000FF\">您的答案:    </font>%@     </a><img src=\"%@\" width=\"18\"></p><p><a><font color=\"#0000FF\">知识点:</font>%@</a></p><p><a><font color=\"#0000FF\">正确答案:</font>%@</a></p><a><font color=\"#0000FF\">试题分析:</font> %@</a>",selectionStr,imageStr,[dataDict objectForKey:@"category_name"],answer,[dataDict objectForKey:@"analysis"]];
//        }else if([qtype isEqualToString:@"2"]){
//            NSString *str = [NSString stringWithFormat:@"%@.%@",orderIdStr,titleStr];
//            CGSize size_0 = CGSizeMake(FMSCREENWIDTH-20, 1000);
//            CGSize size = [str sizeWithFont:[UIFont systemFontOfSize:16.0]constrainedToSize:size_0 lineBreakMode:NSLineBreakByWordWrapping];
//            
//            h = size.height+30;
//            //        NSMutableString *answerS = [NSMutableString stringWithCapacity:1];
//            //        for (NSString *answerStr in  self.answerArray) {
//            //            [answerS appendFormat:@"%@.",answerStr];
//            //        }
//            NSMutableString *outputAfter = [[NSMutableString alloc] init];
//            for(NSString *str in self.answerArray){
//                [outputAfter appendFormat:@"%@",str];
//            }
//            FMSCHBLog(@"排序后:%@",outputAfter);
//            NSString *ans = nil;
//            NSString *imageStr = nil;
//            if (answer.length>7) {
//                NSRange range;
//                range.length = answer.length-7;
//                range.location = 3;
//                answer = [answer substringWithRange:range];
//            }
//            if (outputAfter.length>0) {
//                if ([outputAfter isEqualToString:answer]) {
//                    imageStr = @"table_no.png";
//                    
//                }else{
//                    imageStr = @"table_yes.png";
//                    
//                }
//                ans = [NSString stringWithFormat:@"%@",outputAfter];
//            }else{
//                ans = @"您没有选择答案";
//                imageStr = @"table_yes.png";
//            }
//            FMSCHBLog(@"answer:%@",ans);
//            
//            anyliseHTMLData = [NSString stringWithFormat:@"<p><a><font color=\"#0000FF\">您的答案:    </font>%@     </a><img src=\"%@\" width=\"18\"></p><p><a><font color=\"#0000FF\">知识点:</font>%@</a></p><p><a><font color=\"#0000FF\">正确答案:</font>%@</a></p><a><font color=\"#0000FF\">试题分析:</font> %@</a>",ans,imageStr,[dataDict objectForKey:@"category_name"],answer,[dataDict objectForKey:@"analysis"]];
//        }
//        CGSize anyliseSize = [anyliseHTMLData sizeWithFont:[UIFont systemFontOfSize:15.0] constrainedToSize:CGSizeMake(FMSCREENWIDTH-20, 1000)];
//        PaperListView *paperList = (PaperListView *)[_swipeView itemViewAtIndex:_swipeView.currentItemIndex];
//        FMSCHBLog(@"paperList:----x--->%f",paperList.frame.origin.x);
//        FMSCHBLog(@"paperList:----y--->%f",paperList.frame.origin.y);
//        UILabel *lineLabel = (UILabel *)[paperList viewWithTag:1000];
//        [lineLabel setHidden:NO];
//        
//        UIWebView *webView = (UIWebView *)[paperList viewWithTag:1001];
//        [webView setHidden:NO];
//        [webView setBackgroundColor:[UIColor clearColor]];
//        [webView loadHTMLString:anyliseHTMLData baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
//        [paperList setContentSize:CGSizeMake(FMSCREENWIDTH-20,webView.frame.origin.y+webView.scrollView.contentSize.height)];
//    }else{
//        CaseQuestionView *plist = (CaseQuestionView *)[_swipeView itemViewAtIndex:_swipeView.currentItemIndex];;
//        if (plist) {
//            [plist showAnswer];
//        }
//    }
//}
- (void)HBTableViewFooterView:(HBTableViewFooterView *)footerView webViewDidFinishLoad:(UIWebView *)webView{
    HBListTableView *tableView = (HBListTableView *)[_swipeView itemViewAtIndex:currentPage];
    tableView.tableFooterView = footerView;
}
-(void)answerBtnClicked:(UIButton *)sender{
    NSDictionary *dataDict = [self.paperArray objectAtIndex:currentPage];
    NSString *collection_finish_flag = [dataDict objectForKey:@"collection_finish_flag"];
    if (IS_STUDY) {
        if (![collection_finish_flag isEqualToString:@"3"]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"作业未提交,不能查看答案。" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
            return;
        }
    }
    HBListTableView *tableView = (HBListTableView *)[_swipeView itemViewAtIndex:currentPage];
    HBTableViewFooterView *footerView = [[HBTableViewFooterView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
    [footerView setDelegate:self];
    [footerView setDataReload:dataDict];
    tableView.tableFooterView = footerView;
}
//收藏
-(void)favBtnClicked:(UIButton *)sender{
    NSMutableDictionary *dataDict = (NSMutableDictionary *)[self.paperArray objectAtIndex:currentPage];
    if (!dataDict) {
        return;
    }
    NSString *qstId =[dataDict objectForKey:@"qstId"];
    NSString *paperId = [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"paper_id"]];
    NSString *favourite_flag = [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"favourite_flag"]];
    BOOL isCollection = NO;
    if ([favourite_flag isEqualToString:@"1"]) {
        isCollection = YES;
    }
    if (!isCollection) {
        if ([Sqlite updateCollection:@"1" orderId:qstId paperId:paperId]) {
            [ApplicationUtils makeToast:@"收藏成功" withImageName:@"Star" withView:self.view];
            FMSCHBLog(@"收藏成功");
            [dataDict setObject:@"1" forKey:@"favourite_flag"];
        }else{
            [ApplicationUtils makeToast:@"收藏失败!" withImageName:@"Star" withView:self.view];
            FMSCHBLog(@"收藏失败");
        }
    }else{
        if ([Sqlite updateCollection:@"0" orderId:qstId paperId:paperId]) {
            FMSCHBLog(@"取消收藏");
            [ApplicationUtils makeToast:@"取消收藏!" withImageName:@"Star" withView:self.view];
            [dataDict setObject:@"0" forKey:@"favourite_flag"];
        }else{
            [ApplicationUtils makeToast:@"取消收藏失败!" withImageName:@"Star" withView:self.view];
            FMSCHBLog(@"取消收藏失败!");
        }
    }
    [sender setSelected:!isCollection];
}
//下一页
-(void)downBtnClicked:(UIButton *)sender{
    if ([self.paperArray count]-1 == currentPage) {
        [ApplicationUtils makeToast:@"已最后一页" withImageName:@"no" withView:self.view];
        return;
    }
    [_swipeView scrollToPage:currentPage+1 duration:0.5];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    FMSCHBLog(@"------urlDict---%@",_urlDict);
    [self initSelfView];
    currentPage = 0;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    if (IS_STUDY) {
//        
//    }else{
//        self.navigationController.navigationBarHidden = NO;
//    }
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    if (IS_STUDY) {
//        
//    }else{
//        self.navigationController.navigationBarHidden = YES;
//    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc{
    _urlDict = nil;
    self.paperArray = nil;
    for (UIView *subView in [self.swipeView subviews]) {
        [subView removeFromSuperview];
    }
    self.swipeView = nil;
    self.answerArray = nil;
    self.listArray = nil;
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
{
    return [self.paperArray count];
}
#pragma mark  SwipeViewDelegate
#pragma -
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    NSMutableDictionary *dataDict = [self.paperArray objectAtIndex:index];
    HBListTableView *tableView = [[HBListTableView alloc] initWithFrame:CGRectMake(0, 0, FMSCREENWIDTH, swipeView.frame.size.height) style:UITableViewStylePlain];
    tableView.tableType = HBListTableViewTypeExercise;
    tableView.isShowSimple = YES;
    [tableView setModelViewData:dataDict WithQuestionCount:self.paperArray.count];
    [tableView setHbdelegate:self];
    return tableView;
}
//- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
//{
//    //    currentPage = index;
//    NSMutableDictionary *dataDict = [self.paperArray objectAtIndex:index];
//    PaperListView *listView = (PaperListView *)view;
//    NSString *qtype =[dataDict objectForKey:@"qtype"];
//    //试题
//    if ([qtype isEqualToString:@"1"]||[qtype isEqualToString:@"2"]||[qtype isEqualToString:@"3"]) {
//        [dataDict addEntriesFromDictionary:[NSDictionary dictionaryWithObject:[dataDict objectForKey:@"content"] forKey:@"questionContent"]];
//        NSString *option_a = [dataDict objectForKey:@"option_a"];
//        NSString *option_b = [dataDict objectForKey:@"option_b"];
//        NSString *option_c = [dataDict objectForKey:@"option_c"];
//        NSString *option_d = [dataDict objectForKey:@"option_d"];
//        NSString *option_e = [dataDict objectForKey:@"option_e"];
//        NSString *option_f = [dataDict objectForKey:@"option_f"];
//        
//        NSMutableArray *array_option = [NSMutableArray arrayWithCapacity:1];
//        if (option_a&&![option_a isEqualToString:@"(null)"]) {
//            [array_option addObject:option_a];
//        }
//        if (option_b&&![option_b isEqualToString:@"(null)"]) {
//            [array_option addObject:option_b];
//        }
//        if (option_c&&![option_c isEqualToString:@"(null)"]) {
//            [array_option addObject:option_c];
//        }
//        if (option_d&&![option_d isEqualToString:@"(null)"]) {
//            [array_option addObject:option_d];
//        }
//        if (option_e&&![option_e isEqualToString:@"(null)"]) {
//            [array_option addObject:option_e];
//        }
//        if (option_f&&![option_f isEqualToString:@"(null)"]) {
//            [array_option addObject:option_f];
//        }
//        [dataDict addEntriesFromDictionary:[NSDictionary dictionaryWithObject:array_option forKey:@"options"]];
//        FMSCHBLog(@"log------>cui:%@",  _urlDict);
//        NSString *qtype = [dataDict objectForKey:@"qtype"];
//        BOOL isSingle = YES;
//        if ([qtype isEqualToString:@"1"]||[qtype isEqualToString:@"3"]) {
//            isSingle = YES;
//        }else if([qtype isEqualToString:@"2"]){
//            isSingle = NO;
//        }else{
//            
//        }
//        listView = [[PaperListView alloc] initWithFrame:CGRectMake(0, 0, FMSCREENWIDTH, swipeView.frame.size.height)isSingle:isSingle isShowAnswer:NO anlysise:YES dataDict:dataDict];
//        [listView setPaperDelegate:self];
//        listView.paperDict = [self.paperArray objectAtIndex:index];
//        [listView setBackgroundColor:[UIColor clearColor]];
//        [listView setTag:100];
//        return listView;
//    }else{
//        NSMutableDictionary *anlysisDict =[self.paperArray objectAtIndex:index];
//        CaseQuestionView  *caseView = [[CaseQuestionView alloc] initWithFrame:CGRectMake(0, 0, FMSCREENWIDTH, swipeView.frame.size.height) isSingle:NO isShowAnswer:NO anlysise:NO dataDict:anlysisDict];
//        [caseView setBackgroundColor:[UIColor clearColor]];
//        return caseView;
//    }
//    return nil;
//}
- (void)swipeViewCurrentItemIndexDidChange:(SwipeView *)swipeView
{
    //更新收藏按钮
    currentPage =swipeView.currentItemIndex;
    NSMutableDictionary *dataDict = [self.paperArray objectAtIndex:currentPage];
    NSString *paper_title = [dataDict objectForKey:@"paper_title"];
    NSString *paperTitleAndCount = [NSString stringWithFormat:@"%@ 共%02li/%02lu题",paper_title,currentPage+1,(unsigned long)[self.paperArray count]];
    CGSize size = [paperTitleAndCount sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:CGSizeMake(FMSCREENWIDTH-80, 35) lineBreakMode:NSLineBreakByWordWrapping];
    [titleLabel setText:paperTitleAndCount];
    [titleLabel setFrame:CGRectMake(10, (MAX(titleLabel.frame.size.height, 30)-size.height)/2, size.width, size.height)];
    
    NSString *favourite_flag = [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"favourite_flag"]];
    BOOL isCollection = NO;
    if ([favourite_flag isEqualToString:@"1"]) {
        isCollection = YES;
    }
    [collectionBtn setSelected:isCollection];
    
    selectionStr = nil;
    [self.answerArray removeAllObjects];
    currentPage = swipeView.currentItemIndex;
    FMSCHBLog(@"CHB--------->:%s",__FUNCTION__);
    //update page control page
    if (swipeView.currentItemIndex==0&&currentPage==swipeView.currentItemIndex) {
        [ApplicationUtils makeToast:@"已第一页" withImageName:@"no" withView:self.view];
        return;
    }
    if ([self.paperArray count]-1 == swipeView.currentItemIndex) {
        [ApplicationUtils makeToast:@"已最后一页" withImageName:@"no" withView:self.view];
        return;
    }
}
-(void)swipeViewWillBeginDragging:(SwipeView *)swipeView{
    
}
- (void)swipeViewDidScroll:(SwipeView *)swipeView{
    //    [self.answerArray removeAllObjects];
    FMSCHBLog(@"swipeViewDidScroll");
}

- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index
{
    FMSCHBLog(@"Selected item at index %i", index);
}
#pragma HBListTableViewDelegate
-(void)HBListTableView:(HBListTableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath userAnswer:(NSString *)userAnswer{
    NSMutableDictionary *dataDict_user = (NSMutableDictionary *)[self.paperArray objectAtIndex:currentPage];
    NSString *qtype = [dataDict_user objectForKey:@"qtype"];
    if ([qtype isEqualToString:@"1"]||[qtype isEqualToString:@"3"]||[qtype isEqualToString:@"0"]) {//0是简答题
        //        if (!isExercise) {
        [dataDict_user setObject:userAnswer forKey:@"user_answer"];
        [self.paperArray replaceObjectAtIndex:currentPage withObject:dataDict_user];
    }
}
#pragma -PaperListViewDelegate
#pragma --
-(void)selectBtnClicked:(ISMutileButton *)sender{
    NSString *title_id = [NSString stringWithFormat:@"%d",currentPage];
    if (sender.isMultile) {
        NSMutableDictionary *dataDict_user = (NSMutableDictionary *)[self.paperArray objectAtIndex:currentPage];
        XingAndLabel_UIView  *titleLableView_ = (XingAndLabel_UIView *)sender.superview;
        NSString *optionsStr_ =titleLableView_.titleLabel.text;
        NSString *selectionStr_ = [[optionsStr_ componentsSeparatedByString:@"."] objectAtIndex:0];
        //            [dataDict_user setObject:selectionStr_ forKey:@"user_answer"];
        [self.paperArray replaceObjectAtIndex:currentPage withObject:dataDict_user];//保存内存中的数组，以便返回上页时出现没有选择情况
        
        NSMutableDictionary *dataDict = (NSMutableDictionary *)[self.paperArray objectAtIndex:currentPage];
        noSelected = 0;
        NSString *answer = [dataDict objectForKey:@"answer"];
        FMSCHBLog(@"answer-------%@",answer);
        NSRange range;
        if (answer.length>3) {
            range.location =3;
            range.length =1;
        }else{
            range.location =0;
            range.length =answer.length;
        }
        answer = [answer substringWithRange:range];
        FMSCHBLog(@"answer---substringWithRange----%@",answer);
        NSArray  *optionsArray = [dataDict objectForKey:@"options"];
        XingAndLabel_UIView  *titleLableView = (XingAndLabel_UIView *)sender.superview;
        NSString *optionsStr =titleLableView.titleLabel.text;
        selectionStr = [[optionsStr componentsSeparatedByString:@"."] objectAtIndex:0];
        NSString *paperId = [NSString stringWithFormat:@"%@",[_urlDict objectForKey:@"exerciseID"]];
        //            [_swipeView scrollToPage:currentPage+1 duration:0.5];
        [self answerBtnClicked:nil];
    }else{
        noSelected = 0;
        NSDictionary *dataDict = [self.paperArray objectAtIndex:currentPage];
        NSString *answer = [dataDict objectForKey:@"answer"];
        XingAndLabel_UIView  *titleLableView = (XingAndLabel_UIView *)sender.superview;
        NSString *optionsStr =titleLableView.titleLabel.text;
        FMSCHBLog(@"optionsStr==%@",optionsStr);
        selectionStr = [[optionsStr componentsSeparatedByString:@"."] objectAtIndex:0];
        if (!self.answerArray) {
            self.answerArray = [NSMutableArray arrayWithCapacity:1];
        }
        if (![self.answerArray containsObject:selectionStr]) {
            [self.answerArray addObject:selectionStr];
        }else{
            [self.answerArray removeObject:selectionStr];
        }
        [self.answerArray  sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];//升序
        NSMutableString *outputAfter = [[NSMutableString alloc] init];
        for(NSString *str in self.answerArray){
            //            [outputAfter appendFormat:@"%@.",str];
            [outputAfter appendFormat:@"%@",str];//1、	多选题即便是选择对了，也会判断该题错误。练习模式下是对的
        }
        FMSCHBLog(@"排序后:%@",outputAfter);
        NSString *ans = nil;
        NSString *imageStr = nil;
        if (answer.length>7) {
            NSRange range;
            range.length = answer.length-7;
            range.location = 3;
            answer = [answer substringWithRange:range];
        }
        if (outputAfter.length>0) {
            ans = [outputAfter substringToIndex:outputAfter.length];//截取后的字符串
        }
    }
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    
}

@end
